// 数字签名 执行文件 sign-exe.cjs
// 推荐使用管理员权限打开 执行  node neutralinojs/resources/js/sign-exe.cjs
const { execSync } = require('child_process');
const path = require('path');

// 项目根目录
const projectRoot = path.resolve(__dirname, '../../../');

// 证书路径
const pfxPath = path.join(projectRoot, 'pfx', 'GUANG_AMS.pfx');

// exe 路径
const exePath = path.join(
  __dirname,
  '..', '..', 'dist', 'neutralinodesktop', 'neutralinodesktop-win_x64.exe'
);

// 签名命令
const signCmd = `signtool sign /f "${pfxPath}" /p "guangxuejian" /tr http://timestamp.digicert.com /td sha256 /fd sha256 /v "${exePath}"`;

try {
  execSync(signCmd, { stdio: 'inherit' });
  console.log('签名成功！');
} catch (err) {
  console.error('签名失败：', err);
  process.exit(1);
}

